package de.herzog.bbp.view.column;

import javafx.scene.control.TableColumn;
import javafx.scene.control.cell.PropertyValueFactory;
import de.herzog.bbp.view.bean.SpielBean;
import de.herzog.bbp.view.javafx.AbstractStringConverter;
import de.herzog.bbp.view.javafx.AutoCompleteListFactory;
import de.herzog.bbp.view.javafx.EditingTableCell;
import de.herzog.bbp.view.javafx.Validator;

public abstract class AbstractColumn<T> extends TableColumn<SpielBean, T> {

	public AbstractColumn() {
		super();
	}

	public AbstractColumn(String text) {
		super(text);
	}

	protected abstract AutoCompleteListFactory<SpielBean, T> getAutoCompleteListFactory();

	protected abstract AbstractStringConverter<SpielBean, T> getStringConverter();

	protected abstract Validator getValidator();

	public void initializeColumn(final String propertyName, boolean editable) {
		setId(propertyName);
		setEditable(editable);
		setCellValueFactory(new PropertyValueFactory<SpielBean, T>(propertyName));
		if (editable) {
			setCellFactory(callback -> new EditingTableCell<>(getValidator(), getStringConverter(),
					getAutoCompleteListFactory()));
		}
	}
}
